package com.example.emos.api.controller;

import cn.hutool.json.JSONUtil;
import com.example.emos.api.common.util.PageUtils;
import com.example.emos.api.common.util.R;
import com.example.emos.api.controller.form.SelectExamineeBypagesForm;
import com.example.emos.api.controller.form.SelectExamineeForm;
import com.example.emos.api.service.ExamineeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;

/**
 * @author ：Supyo
 * @date ：Created in 2021/11/16 14:41
 * @description：
 */
@RestController
@RequestMapping("/examinee")
@Tag(name = "ExamineeController", description = "查看评分接口")
@Slf4j
public class ExamineeController {

    @Autowired
    private ExamineeService examineeService;

    @PostMapping("/selectExamineeBypages")
    @Operation(summary = "评分分页查询")
    public R selectExamineeBypages(@Valid @RequestBody SelectExamineeBypagesForm form) {
        int page = form.getPage();
        int length = form.getLength();
        int start = (page - 1) * length;
        HashMap param = JSONUtil.parse(form).toBean(HashMap.class);
        param.put("start", start);
        PageUtils pageUtils = examineeService.selectExamineeBypages(param);
        return R.ok().put("page", pageUtils);
    }


    @PostMapping("/selectExaminee")
    @Operation(summary = "查看评分明细")
    public R selectExaminee(@Valid @RequestBody SelectExamineeForm form) {
        HashMap map = examineeService.selectExaminee(form);
        return R.ok().put("data", map);
    }
}
